package com.han.hotelplat.service.question.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.han.hotelplat.comm.Constant;
import com.han.hotelplat.comm.base.EntityManage;
import com.han.hotelplat.comm.base.Pager;
import com.han.hotelplat.pojo.employee.Employee;
import com.han.hotelplat.pojo.hotelmanager.Hotelmanager;
import com.han.hotelplat.pojo.question.Question;
import com.han.hotelplat.service.employee.EmployeeService;
import com.han.hotelplat.service.hotelmanager.HotelmanagerService;
import com.han.hotelplat.service.question.QuestionService;

@Service
public class QuestionServiceImpl implements QuestionService{
	@Autowired
	private EntityManage entityManage;
	@Autowired
	private EmployeeService employeeService;
	@Autowired
	private HotelmanagerService hotelmanagerService;
	
	@Override
	public void save(Question q) {
		entityManage.save(q);
	}
	
	@Override
	public Pager<Question> getAllQuestionByPage(Integer pageNo,
			String startTime, String endTime, String tel, Integer state) {
		String hql = "From Question where 1=1 ";
		if(state != null && state.intValue()>0){
			hql = hql +" and state = "+state;
		}
		hql = hql +" order by creattime desc";
		Pager<Question> data = entityManage.findByHqlForPage(hql, pageNo, (short)20);
		for(Question q : data.getList()){
			if(q.getUsertype().intValue() == Constant.USER_TYPE_EMPLOYEE.intValue()){
				Employee em = employeeService.getEmployee(q.getUserid());
				q.setUsername(em==null?"":em.getTel());
				q.setUsertypename("帮工端");
			}
			if(q.getUsertype().intValue() == Constant.USER_TYPE_EMPLOYEE.intValue()){
				Hotelmanager hm = hotelmanagerService.findByUserid(q.getUserid());
				q.setUsername(hm==null?"":hm.getTel());
				q.setUsertypename("酒店端");
			}
		}
		return data;
	}

}
